﻿namespace Dissemination.MVC.MVCContrib.CallHandlers
{
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using Microsoft.Practices.Unity.InterceptionExtension;
    using Microsoft.Practices.Unity;
    using UnityContrib.Interfaces;
    using UnityContrib.Types;

    /// <summary>
    /// Controller Matching Rule
    /// </summary>
    public class ControllerMatchingRule : IMatchingRule
    {
        /// <summary>
        /// Gets or sets the logger.
        /// </summary>
        /// <value>The logger.</value>
        [Dependency]
        public ILoggerFacade Logger { get; set; }

        /// <summary>
        /// Tests to see if this rule applies to the given member.
        /// </summary>
        /// <param name="member">Member to test.</param>
        /// <returns>
        /// true if the rule applies, false if it doesn't.
        /// </returns>
        public bool Matches(System.Reflection.MethodBase member)
        {
            // We're only interested in IControllerFactory (not 
            // the DefaultControllerFactory which will also pass through here)
            if (!member.DeclaringType.FullName.Contains("IControllerFactory"))
                return false;

            Logger.Log(string.Format("ControllerMatchingRule.Matches(member=[{0}])",
                member.DeclaringType.FullName), 
                Category.Debug, Priority.None);
            
            return true;
        }

    }
}
